package vn.edu.saigontech.ncms.web.program;

import vn.edu.saigontech.ncms.service.LevelService;
import vn.edu.saigontech.ncms.util.Checker;
import vn.edu.saigontech.ncms.web.AbstractValidator;

@SuppressWarnings("serial")
public class ValidateLevelAction extends AbstractValidator {
	
	private Long id;
	private String name;
	private String weeks;
	private String hours;
	private String minScore;
	private String maxScore;
	private String tuition;

	public String check() {
		if(Checker.isEmpty(this.name)) {
			this.sendKeyError("validator.required", "name");
		}
		if(Checker.isNull(this.id)) {
			if(!Checker.isNull(LevelService.INSTANCE.findByName(this.name))) {
				this.sendKeyError("validator.exist", "name");
			}
		}
		if(!Checker.isInteger(this.hours) || !Checker.isPositive(this.hours)) {
			this.sendKeyError("validator.invalid", "hours");
		}
		if(!Checker.isInteger(this.weeks) || !Checker.isPositive(this.weeks)) {
			this.sendKeyError("validator.invalid", "weeks");
		}
		if(!Checker.isEmpty(this.minScore)) {
			if(!Checker.isDouble(this.minScore) || !Checker.isPositive(this.minScore)) {
				this.sendKeyError("validator.invalid", "minScore");
			}
		}
		if(!Checker.isEmpty(this.maxScore)) {
			if(!Checker.isDouble(this.maxScore) || !Checker.isPositive(this.maxScore)) {
				this.sendKeyError("validator.invalid", "maxScore");
			}
		}
		if(!Checker.isDouble(this.tuition) || !Checker.isPositive(this.tuition)) {
			this.sendKeyError("validator.invalid", "tuition");
		}
		return this.toSuccess();
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getWeeks() {
		return weeks;
	}

	public void setWeeks(String weeks) {
		this.weeks = weeks;
	}

	public String getHours() {
		return hours;
	}

	public void setHours(String hours) {
		this.hours = hours;
	}

	public String getMinScore() {
		return minScore;
	}

	public void setMinScore(String minScore) {
		this.minScore = minScore;
	}

	public String getMaxScore() {
		return maxScore;
	}

	public void setMaxScore(String maxScore) {
		this.maxScore = maxScore;
	}

	public String getTuition() {
		return tuition;
	}

	public void setTuition(String tuition) {
		this.tuition = tuition;
	}
}
